Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve yaml serialization quoting #4217

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sigurdm
Copy link
Contributor

@sigurdm sigurdm commented Apr 11, 2024

#4214

We should only merge this if we want accept disturbing almost all pubspec.locks.

Maybe we can bundle it with another update to pubspec.lock structure.

We can also make a smalller update that just fixes bugs.

Copy link
Member

@lrhn lrhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Drive-by-comments. I saw a regexp, so I had to say something.)

'null', 'Null', 'NULL',
].contains(s)) return true;
// Numbers must be quoted
if (RegExp(r'^[-+]?[0-9]*\.?[0-9]*(e[0-9]+)?$').hasMatch(s)) return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a potentially dangerous RegExp because of the \d*\.?\d* sequence. It's probably not exponential, but it can be quadratic in the length to reject something like 00000000000000000000000....0000000x

Consider changing to \d*(\.\d*)? (And be aware that it still matches . alone.)

// Numbers must be quoted
if (RegExp(r'^[-+]?[0-9]*\.?[0-9]*(e[0-9]+)?$').hasMatch(s)) return true;
// Hex numbers must be quoted
if (RegExp(r'^0x[0-9]+$').hasMatch(s)) return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be [0-9a-fA-F].

/// which means some strings may be unnecessarily quoted.
bool _needsYamlQuotes(String s) {
// These must be quoted
if ([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List can be const. (Small save, but save, over creating a new list on every invocation.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants